package modules.scripts;

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;

import miscellaneous.Sequence;
import miscellaneous.SequenceFileWriter;
import miscellaneous.SimpleFileIO;

public class SequenceFileExtractor {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			String line;
			String path = "/Users/rhali/Desktop/ResolvedPillars/GFCSuperset/";
			/*String sequenceFile = "QueryYeast.fasta";
			String fileName = "YGOBPillarsNotInGFC.txt";
			SimpleFileIO reader = new SimpleFileIO();
			reader.readSequenceFile(path, sequenceFile);
			ArrayList<Sequence> sequences = reader.getSequences();
			BufferedReader bufferedreader = new BufferedReader(new FileReader(path + fileName));
			int count = 1;
			while ((line = bufferedreader.readLine()) != null) {
				String[] strArr = line.split("\t");
				for(int i = 0; i < strArr.length; i++) {
					for(int j = 0; j < sequences.size(); j++) {
						if(sequences.get(j).getIdentifier().equals(strArr[i])) {
							if(sequences.get(j).getIdentifier().equals(strArr[i])) {
								String[] strArr1 = strArr[i].split("\\.");
								if(strArr1[0].equals("0"))
									strArr[i] = "Cgl" + strArr[i];
								else if(strArr1[0].equals("1"))
									strArr[i] = "Ecy" + strArr[i];
								else if(strArr1[0].equals("2"))
									strArr[i] = "Ego" + strArr[i];
								else if(strArr1[0].equals("3"))
									strArr[i] = "Kaf" + strArr[i];
								else if(strArr1[0].equals("4"))
									strArr[i] = "Kla" + strArr[i];
								else if(strArr1[0].equals("5"))
									strArr[i] = "Kan" + strArr[i];
								else if(strArr1[0].equals("6"))
									strArr[i] = "Lkl" + strArr[i];
								else if(strArr1[0].equals("7"))
									strArr[i] = "Lth" + strArr[i];
								else if(strArr1[0].equals("8"))
									strArr[i] = "Lwa" + strArr[i];
								else if(strArr1[0].equals("9"))
									strArr[i] = "Nca" + strArr[i];
								else if(strArr1[0].equals("10"))
									strArr[i] = "Nda" + strArr[i];
								else if(strArr1[0].equals("11"))
									strArr[i] = "Sce" + strArr[i];
								else if(strArr1[0].equals("12"))
									strArr[i] = "Sku" + strArr[i];
								else if(strArr1[0].equals("13"))
									strArr[i] = "Smi" + strArr[i];
								else if(strArr1[0].equals("14"))
									strArr[i] = "Suv" + strArr[i];
								else if(strArr1[0].equals("15"))
									strArr[i] = "Tbl" + strArr[i];
								else if(strArr1[0].equals("16"))
									strArr[i] = "Tde" + strArr[i];
								else if(strArr1[0].equals("17"))
									strArr[i] = "Tph" + strArr[i];
								else if(strArr1[0].equals("18"))
									strArr[i] = "Vpo" + strArr[i];
								else if(strArr1[0].equals("19"))
									strArr[i] = "Zro" + strArr[i];
								Sequence seq = new Sequence(strArr[i], sequences.get(j).getSequence());
								SequenceFileWriter.writeAndAppendSequenceInFasta(path, String.valueOf(count) + "YGOB", seq);
								break;
							}
						}
					}
				}
				count++;
			}
			bufferedreader.close();*/
			SequenceFileWriter.writeAndAppendLine(path, "bash.sh", "#!/bin/bash");
			SequenceFileWriter.writeAndAppendLine(path, "bash.sh", "");
			
			for(int i = 1; i < 27; i++) {
				SequenceFileWriter.writeAndAppendLine(path, "bash.sh", "clustal-omega -i " + i + "GFC -o " + i + "GFC.fas");
				SequenceFileWriter.writeAndAppendLine(path, "bash.sh", "FastTree " + i + "GFC.fas > " + i + "GFC.txt");
				SequenceFileWriter.writeAndAppendLine(path, "bash.sh", "java -jar Notung-2.6.jar -g " + i + "GFC.txt -s SpecTreeYeast.nwk --reconcile --root > " + i + "GFCReconciliationAnalysis.txt");
				SequenceFileWriter.writeAndAppendLine(path, "bash.sh", "");
			}
		} catch (Exception e) {
			System.out.println("Error : " + e.getMessage());
		}
	}

}
